package com.xy.blog.user.controller;

import com.xy.blog.core.exception.BaseException;
import com.xy.blog.core.springmvc.controller.BaseController;
import com.xy.blog.core.springmvc.controller.IBaseController;
import com.xy.blog.core.springmvc.result.page.PageReq;
import com.xy.blog.user.controller.model.req.AttrDictReq;
import com.xy.blog.user.controller.model.req.query.AttrDictQuery;
import com.xy.blog.user.mapstruct.AttrDictConverter;
import com.xy.blog.user.service.IAttrDictService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author zanhonglei
 * @version V1.0
 * @Description: 属性字典
 * @date 2019/11/17 4:19 下午
 */
@Api(value = "UserAttrDictController",tags = "属性字典")
@RequestMapping("/v1/attr-dict")
@RestController
public class AttrDictController extends BaseController implements IBaseController<AttrDictQuery, AttrDictReq> {

    @Autowired
    private IAttrDictService attrDictServiceImpl;

    @Autowired
    private AttrDictConverter attrDictConverter;


    @Override
    public Object pages(PageReq<AttrDictQuery> req) throws BaseException {
        return getPageData(attrDictConverter.bo2Vo(attrDictServiceImpl.listByPage(req)));
    }

    @Override
    public Object getById(Long id) throws BaseException {
        return getData(attrDictConverter.bo2Vo(attrDictServiceImpl.getById(id)));
    }

    @Override
    public Object save(@Valid AttrDictReq req) throws BaseException {
        attrDictServiceImpl.saveAttrDict(attrDictConverter.req2Bo(req));
        return success();
    }

    @Override
    public Object update(@Valid AttrDictReq req) throws BaseException {
        attrDictServiceImpl.updateAttrDictById(attrDictConverter.req2Bo(req));
        return success();
    }

    @Override
    public Object deleteById(Long id) throws BaseException {
        attrDictServiceImpl.deleteById(id);
        return success();
    }
}
